package com.ruoyi.quartz.task;

import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.coupons.domain.Coupons;
import com.ruoyi.coupons.domain.CouponsMember;
import com.ruoyi.coupons.service.ICouponsMemberService;
import com.ruoyi.coupons.service.ICouponsService;
import com.ruoyi.product.mapper.StoreProductMapper;
import com.ruoyi.store.domain.Store;
import com.ruoyi.store.mapper.StoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 **/
@Component("vipStateTask")
public class VipStateTask {
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private StoreProductMapper storeProductMapper;
    public void vipStateFlush(){
        Date nowTime=new Date();
        Store storeS=new Store();
        storeS.setVipState(DicConstants.SYS_Y.getCode());
        List<Store> listStore= storeMapper.selectStoreList(storeS);
        for (Store store:listStore) {
           if(DicConstants.SYS_Y.getCode().equals(store.getVipState())){
               if(nowTime.compareTo(store.getVipTime())>0){
                   //过期了
                   //门店vip状态置为过期
                   Store storeUpdate=new Store();
                   storeUpdate.setId(store.getId());
                   storeUpdate.setVipState(DicConstants.SYS_N.getCode());
                   storeMapper.updateStore(storeUpdate);
                   //下架该门店下所有商品
                   storeProductMapper.downProductByStoreId(store.getId());
               }
           }

        }
    }
}
